package com.wenwu.controller.common;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wenwu.common.bean.RelicsBasic;
import com.wenwu.common.bean.RelicsDetail;
import com.wenwu.service.CommonService;

/**
 * @project RelicsProject-web
 * @class CommonController.java
 * @author zhujiagui E-mail:<zhujiagui@zkingsoft.com>
 * @date 2015年5月1日 下午12:44:59
 * @description 公共Controller类
 */
@Controller(value = "CommonController")
@RequestMapping(value = "/mgr/common")
public class CommonController {
	Logger log = Logger.getLogger(this.getClass());
	@Autowired
	private CommonService commonService;

	@RequestMapping(value = "/fileupload")
	public String initPage() {
		log.info("进入附件上传页面...");
		return "common/fileupload";
	}

	@RequestMapping(value = "/addData")
	public void addData(RelicsBasic basic) {
		log.info("测试保存数据(含附件)");
		log.info(basic.toString());
		log.info(basic.getFileList());// 附件集合
		log.info(basic.getFileList().get(0).getAttachmentOwner());
	}

	@RequestMapping(value = "/relicsdetail")
	public String relicsdetail(Model model) throws Exception{
		log.info("进入遗址概况页面...");
		try {
			model.addAttribute("relicsdetail", commonService.selectRelicsDetail());
		} catch (Exception e) {
			model.addAttribute("errorMsg", e.getMessage());
		}
		return "relicsdetail/relicsdetailform";
	}
	@RequestMapping(value = "/addRelicsdetail")
	public String addRelicsdetail(Model model,RelicsDetail detail ) throws Exception{
		log.info("保存遗址概况...");
		try {
			model.addAttribute("relicsdetail", commonService.addRelicsdetail(detail));
		} catch (Exception e) {
			model.addAttribute("errorMsg", e.getMessage());
		}
		return "relicsdetail/relicsdetailform";
	}
}
